<?php
namespace ac\controllers;

use Yii;
use yii\web\Controller;
use ac\component\tool\Tool;
use ac\component\aliyun\Sts;

/*阿里云类*/
class AliController extends Controller
{
    /*获取oss sts*/
    public function actionOssSts()
    {
        $accessKeyId = Yii::$app->params['aliyun']['accessKeyId'];
        $accessKeySecret = Yii::$app->params['aliyun']['accessKeySecret'];
        $stsUrl = Yii::$app->params['aliyun']['sts'];
        $accountID = Yii::$app->params['aliyun']['accountID'];
        $roleName = Yii::$app->params['aliyun']['roleName'][0];

        $sts = new Sts($accessKeyId, $accessKeySecret, $stsUrl, $accountID, $roleName);
        $res = json_decode($sts->getSts());
        // P($res);
        if($res->code == 0){
            $res->data->region = Yii::$app->params['aliyun']['oss']['region'];
            $res->data->bucket = Yii::$app->params['aliyun']['oss']['bucket'];
            // P($res);
            return Tool::showRes([0, '获取成功'], $res->data);
        }
        return Tool::showRes([10005, '失败了']);
    }

    /*阿里云上传之后，需要更新到库里，方便日后统计*/
    public function actionSaveFileInfo()
    {
        P($this->post());
    }

}
